Hello and welcome to this lecture.
In this lecture we will be creating some big game of our logic.
The logic of the game will be that if we allow the ball to touch the bottom of the compass then the
game is lost.
That's the simple logic we are trying to implement in this lecture.
At the moment the ball bounces off the fall was without nothin happening.
What we going to do is make it bounce bounce off only the three walls bigger leaded bounce of the top
left and the right.
What we're going to do.
We going to make him that if he touches the bottom of the Come that's then the game is lost so you've
got to control the ball whether the paddle to make sure it does not touch the bottom of the compass
anytime it touches the bottom.
The game over are you get the popof Same.
The game is over.
That's what we're trying to implement here.
All right this is the java script for the project.
And inside the draw function here.
This piece of code here the one highlighted here.
This is what controls the Bunson of the ball off the four walls of the coverts we are going to amend
this second statement here so that it does not.
So if the ball touches the bottom of the covers we can implement alert that will show when the ball
does the hand it will see Game over.
So we will implement that here by amending this part of the if statement or right.
I have already pre written the code here just to save a bit of time.
So this is what I have done.
This cause was from previous and I amended.
Here we should a second block of code for Bunson the ball off the four walls of the canvas.
So what I have done here on online 61 here have said if the variable y plus the variable D Y is less
than the ball radius.
I want the variable do you want to be equal to minus D y o k.
If that's not the case then if the then I've got an ELSE IF statement which states that if the variable
y blows a variable d y is greater than the height of the canvas minus the ball radius.
If this condition is true thus And then I want I've also implemented.
Be here is for when the ball touches the paddle at the moment there is no inter not in happens when
they interact.
So this here will create some kind of coalition detection between the ball and the paddle.
So when the ball hits the paddle it will bounce off it and get back into the cumbersome plane area.
That's what this bit of code here on line 65 is it.
Ill look listen out for coalition detection between the ball and a paddle.
So if the ball touches a puddle it will bounce back into the player era.
That's what this bit is on online 64 sourcing.
Yeah that's what this line 6 5 6 5 is.
If so this is where the game logic will be implemented to determine to declare the game over.
If the ball touches the bottom of the Come that's a tall alert.
Game over.
I need to reload the game to carry on again.
All right so that's what the call is so the call the code this is a code that will be here 6 5 determines
a coalition.
When the ball hits the pad up to bounce off it.
This court here from line 6 to 1 will all sorts the term in that if the ball touches the bottom of the
comebacks this alert will.
Displaced.
So I'll say that and then we can see the court in that.
Okay.
That's the code in action at the moment.
So if I try and control with my you can see bounces off the time it touches say bounces off the puddle
that's me controlling it with my left or is hit the bottom.
So game over.
So I click okay here reloads the game and we play if will let me touch the bottom of the compass.
It would be the game of US versus me control in the game or I missed that.
So you can have a practice and control the game which your left some movement and the right curve some
movement not allowing it to touch the bottom of the compass touches upon someone to come back.
The game is over.